package com.online.controller;

import com.online.entity.ApiResult;
import com.online.entity.Replay;
import com.online.service.ReplayService;
import com.online.util.ApiResultHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 回复留言
 */
@RestController
public class ReplayController {
    @Autowired
    private ReplayService replayService;

    @PostMapping("/replay")
    public ApiResult add(@RequestBody Replay replay){
        int data=replayService.add(replay);
        if (data!=0){
            return ApiResultHandler.buildApiResult(200,"添加成功",data);
        }else {
            return ApiResultHandler.buildApiResult(400,"添加失败",data);
        }
    }
    @GetMapping("/replay/{messageId}")
    public ApiResult findAllById(@PathVariable("messageId") Integer messageId){
        List<Replay> res=replayService.findAllById(messageId);
        return ApiResultHandler.buildApiResult(200,"根据messageId查询",res);
        }
}
